package com.huizhonglm.diap.presenters.wallet;

import com.alibaba.fastjson.JSON;
import com.bruce.common.utils.EmptyUtil;
import com.huizhonglm.diap.api.API;
import com.huizhonglm.diap.api.CommonResponse;
import com.huizhonglm.diap.api.HttpCallback;
import com.huizhonglm.diap.api.Status;
import com.huizhonglm.diap.api.model.wallet.IntegralCashBackParams;
import com.huizhonglm.diap.presenters.BasePresenter;
import com.huizhonglm.diap.ui.wallet.iView.IntegralCashBackIView;

/**
 * 描述当前类的作用
 *
 * @author LiXiaoLong
 * @version 1.0
 * @since 2016-03-07 13:53
 */
public class IntegralCashBackPresenter extends BasePresenter {

    private IntegralCashBackIView iView;

    public IntegralCashBackPresenter(IntegralCashBackIView iView) {
        this.iView = iView;
    }

    public void onParticipate(String userId, Integer integral){
        IntegralCashBackParams params = new IntegralCashBackParams();
        params.userId = userId;
        params.integral = integral;
        API.http().post("IntegralCashBack", params, new HttpCallback() {
            @Override
            public void onSuccess(String result) {
                if (!EmptyUtil.isEmpty(result)) {
                    CommonResponse resp = JSON.parseObject(result, CommonResponse.class);
                    if (resp != null && Status.SUCCESS.equals(resp.getStatus())) {
                        iView.onParticipateSuccess();
                    } else {
                        iView.onParticipateFailure();
                    }
                } else {
                    iView.onParticipateFailure();
                }
            }

            @Override
            public void onFailure(Throwable ex) {
                iView.onParticipateFailure();
            }
        });
    }
}
